package deadLatch;

/**
 * @author wuhan
 * @date 2019/9/19 13:44
 */

class Test implements Runnable{
    private boolean flag;
    Test(boolean flag){
        this.flag=flag;
    }

    @Override
    public void run() {
        if (flag){
            synchronized (MyLock.locka){
                System.out.println("have locka need lockb ");
                synchronized (MyLock.lockb){
                    System.out.println(" have locka,lockb");
                }
            }
        }
        else {
            synchronized (MyLock.lockb){
                System.out.println("have lockb need locka");
                synchronized (MyLock.locka){
                    System.out.println("have lackb,locka");
                }
            }
        }
    }
}

class MyLock{
      static final Object locka= new Object();
      static final Object lockb= new Object();
}

public class DeadLatch {
    public static void main(String[] args) {
        Thread thread0=new Thread(new Test(true));
        Thread thread1=new Thread(new Test(false));
        thread0.start();
        thread1.start();
    }

}
